import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let defaultCity = '杭州'
try {
  if (localStorage.city) {
    defaultCity = localStorage.city
  }
} catch (error) {
  console.log(error)
}

export default new Vuex.Store({
  state: {
    // city: '上海'// 公共数据
    // city: localStorage.city || '上海'
    city: defaultCity
  },
  actions: {
    cCity (ctx, city) {
      ctx.commit('cCity', city)
    }
  },
  mutations: {
    cCity (state, city) {
      state.city = city
      // localStorage.city = city
      try {
        localStorage.city = city
      } catch (error) {
        console.log(error)
      }
    }
  }
})
// export default new Vuex.Store({
//   state: {
//     // city: '上海'// 公共数据
//     city: localStorage.city || '上海'
//   },
//   actions: {
//     cCity(ctx, city) {
//       ctx.commit('cCity', city)
//     }
//   },
//   mutations: {
//     cCity(state, city) {
//       state.city = city
//       localStorage.city = city
//     }
//   }
// })
